home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / PROBLEMS / EXAMPLE / WIMPAPP
Internet Message Format  |  1992-08-02  |  14KB

  1. From info-admin@newcastle.ac.uk  Mon Aug  3 10:10:06 1992
  2. Received: from dfunms.rus.uni-stuttgart.de by helpdesk.rus.uni-stuttgart.de (5.52/BelWue-1.0SG(subsidiary))
  3.     (for zrzm0111) id AA20429; Mon, 3 Aug 92 10:10:06 MST
  4. Received: from mail.Germany.EU.net by dfunms.rus.uni-stuttgart.de with SMTP id AA29250
  5.   (5.65c/DFUE-M1.0 for <joerg.scheurich@rus.uni-stuttgart.de>); Mon, 3 Aug 1992 10:07:46 +0200
  6. Message-Id: <9208030808.AA04558@mail.Germany.EU.net>
  7. Received: from ben.uknet.ac.uk 
  8.     by mail.Germany.EU.net with SMTP (5.65+/UNIDO-2.1.0.b)
  9.     via EUnet for rus.uni-stuttgart.de
  10.     id AA04558; Mon, 3 Aug 92 10:08:08 +0200
  11. Received: from eros.uknet.ac.uk by ben.uknet.ac.uk via UKIP with SMTP (PP) 
  12.           id <g.08572-0@ben.uknet.ac.uk>; Mon, 3 Aug 1992 09:06:51 +0100
  13. Received: from newcastle.ac.uk by eros.uknet.ac.uk via JANET with NIFTP (PP) 
  14.           id <3079-1@eros.uknet.ac.uk>; Mon, 3 Aug 1992 09:06:42 +0100
  15. Date: Mon, 3 Aug 1992 08:55:54 +0100
  16. Original-Received: 
  17. Pp-Warning: Illegal Received field on preceding line
  18. From: The Newcastle Info-Server <info-admin@newcastle.ac.uk>
  19. To: joerg.scheurich@rus.uni-stuttgart.de
  20. Subject: Re: Request: sources; Topic: archimedes wimpapp2
  21. Sender: info-admin@newcastle.ac.uk
  22. Status: RO
  23.  
  24. Path: newcastle.ac.uk!uknet!mcsun!uunet!comp.vuw.ac.nz!waikato.ac.nz!aukuni.ac.nz!cs18.cs.aukuni.ac.nz!jwil1
  25. >From: jwil1@cs.aukuni.ac.nz (TMOTA)
  26. Newsgroups: comp.sources.acorn
  27. Subject: Source (Arc, BASIC): Wimp example program
  28. Message-ID: <1992Jul15.220305.1513@cs.aukuni.ac.nz>
  29. Date: 15 Jul 92 22:03:05 GMT
  30. Sender: jwil1@cs.aukuni.ac.nz (TMOTA)
  31. Organization: Computer Science Dept. University of Auckland
  32. Lines: 330
  33. Approved: cba@acorn.co.nz
  34.  
  35. Submitted-by: Jason Williams <jwil1@cs.aukuni.ac.nz>
  36.  
  37. A while ago I gave a talk at the local Acorn club about writing WIMP
  38. applications. The following is a very brief handout for the talk,
  39. along with the example program I wrote.
  40.  
  41. (Note: The example program needs an application directory with !Sprites,
  42. !Run, and Templates files... The binary of this application will be posted
  43. on comp.binaries.acorn: This message is intended as read-only material!)
  44.  
  45. --->8---
  46.  
  47. This program is Freeware. Do what you like with it, so long as you don't
  48. make any profit out of it.
  49.  
  50. This is a small application written as a sort of tutorial on WIMP
  51. programming in BASIC. I have tried to keep it simple while getting
  52. as far as the basic necessities for your average application.
  53. I hope it will help you to learn the basics of WIMP programming.
  54.  
  55.  
  56. Application directories
  57. =======================
  58.  
  59. Application directory: Always a directory with a '!' as the first
  60. character of its name. Open this up by holding down shift while
  61. double-clicking the application icon.
  62.  
  63. Inside, there are usually the following files:
  64. !Boot     A file that is run when the application is first "seen" by the
  65.       filer. Usually an Obey file.
  66. !Run      A file that is run when the user double-clicks (runs) the
  67.       application. Usually an Obey file.
  68. !Help     A file/application that is run when the user selects the 'help'
  69.       option from the filer menu. Usually a text file.
  70. !Sprites  A Sprite file containing the sprites needed for the application.
  71.       Usually two mode-12 sprites, a 34x17 one (!appname), and a
  72.       smaller one (19x9) called sm!appname.
  73.       (Under RISC OS 3.xx, there are 2 additional files, !Sprites22,
  74.       which should contain sprites defined in mode 20 (34x34), and
  75.       !Sprites23, which should contain a 34x34 black and white sprite
  76.       defined in mode 23. These files are optional but recommended)
  77. !RunImage The main program to be run when the application is run.
  78.       This will be run by the !Run file. (see below)
  79. Templates A file defining the size and shape of the windows used by the
  80.       application. This can be edited with !FormEd, and is the
  81.       easiest way to create your window layouts. You can also edit the
  82.       window layouts for your other applications by editing their
  83.       Template files - but remember to keep a copy of the original    
  84.       templates just in case!
  85.  
  86. Obey Files
  87. ==========
  88. These are files containing operating system '*' commands (much like a
  89. BBC's EXEC text files, but the commands are not echoed to the screen
  90. when the file is run). They can be edited (as text files)  by dragging
  91. them to !Edit. Typical things to find in application Obey files are:
  92. <Obey$Dir>
  93.                   This expands to the application
  94.                   directory's full pathname 
  95.                   when the Obey file is run.
  96. IconSprites <Obey$Dir>.!Sprites   Tell the WIMP to load the sprite file
  97.                   !Sprites into the icon- sprite area.
  98.                   (i.e. load your app's icons into memory)
  99. WimpSlot -min 64k -max 128k       This tells the Wimp that you need a
  100.                   minimum of 64 kilobytes, and a maximum
  101.                   of 128 kilobytes of memory before you
  102.                   can be run.
  103. Run <Obey$Dir>.!RunImage          Run the program called !Runimage in
  104.                   the same directory as the Obey file.
  105.  
  106. The BASIC !RunImage
  107. ===================
  108. This is the actual application. The next page has an example application
  109. !RunImage program in  BASIC, showing the basics that you need to get
  110. started.
  111.  
  112.  
  113. WIMP POLL result blocks
  114. =======================
  115. When we poll the WIMP, it returns events to us under the following
  116. categories (and more):
  117.  
  118. 0    Null (Nothing has happened - these are only received if the machine
  119.      is idling)
  120.  
  121. 1    A window needs redrawing (Only received if you have
  122.      non-auto-redraw windows - this can be set in the Tempate editor)
  123.  
  124. 2    A window needs (re)opening. (A window is being opened/moved/resized)
  125.  
  126. 3    A window needs closing (the user has clicked it's close box)
  127.  
  128. 6    Mouse button press/release
  129.  
  130. 9    A menu item has been chosen (Can only happen after you have popped
  131.      up a menu!)
  132.  
  133. 17  A message from another task has arrived
  134. 18  A message from another task has arrived. An acknowledging message is
  135.     expected if you are interested in the operation they request.
  136.  
  137. For our simple application, we are only interested in a few of the event
  138. types returned. When we receive the event, the WIMP fills in extra
  139. useful information about the event into the  block we give it. The
  140. useful block contents for the various events we are interested in are as 
  141. follows:
  142.  
  143. For OpenWindow and CloseWindow (result = 2, 3) events,
  144.   block!0 = the window handle.
  145. If we don't want to check anything before allowing the window to be
  146. resized/closed/etc, then all we need to do is pass the block back to the
  147. WIMP (more or less saying "that's OK by me: go ahead  and open/close the
  148. window), then we just call Wimp_OpenWindow or Wimp_CloseWindow. (Note
  149. that if we don't do this, people will be unable to even MOVE or close
  150. our windows!)
  151.  
  152. For Mouse events (result = 6), we get the following information:
  153.   block!0   =  mouse x
  154.   block!4   =  mouse y
  155.   block!8   =  new button state
  156.   block!12 =  window handle mouse is in
  157.   block!16 =  icon handle mouse is in
  158. We usually check the button state for Select or Menu clicks. In the
  159. example program, a Menu click  calls the code to pop up our menu, while
  160. a Select/Adjust click makes us ask the WIMP to open  our main window.
  161. The x,y positions are used only by the menu creation code to position
  162. the  menu in the correct place.
  163.  
  164. For menu events (result = 9), the block contains a list (terminated by
  165. a value of -1) of menu items and  subitems that were selected.
  166. Each number represents one menu, with the first item being number 0,
  167. the second number 1, etc. Thus for our simple menu the choices returned
  168. would either be 0  (Info, for which we take no action), or 1 (quit, for
  169. which we set our "quit%" variable so that after  processing this event,
  170. our main event loop will stop).
  171. If a submenu is involved, then the first value (block%!0) is the main
  172. menu item from which the submenu "hangs", and the second value 
  173. (block%!4) would be the item number within the submenu.
  174.  
  175. Message events (result = 17 or 18) allow many fancy inter-application
  176. communications: Our only  interest now is the message number 0
  177. (block%!16 = 0), which is the "quit" message, sent by the  task manager
  178. if the user selects "quit" from the menu popped up over the
  179. application's name in  the task manager window. This is a very important
  180. thing to include, as it is very simple, but  allows you to quit your
  181. application during development, even if it doesn't yet supply a menu!
  182.  
  183. ---
  184.  
  185. More information on these things can be found in back-issues of RISC
  186. USER, Archive, BBC Acorn User,  or from me if you ask really nicely!
  187. (The Programmers Reference Guide may also be of some help ;-)
  188.  
  189. Sorry about the brevity of this description, but this was originally
  190. written as a handout for talk I gave at the local Acorn club...
  191.  
  192. However, I have written the !RunImage program as simply as I can, to make
  193. it as clear and a easy to understand as possible.
  194.  
  195. Jason Williams.
  196.  
  197. --->8---
  198.  
  199. REM > !Example.!RunImage <
  200. REM Example WIMP application
  201. REM Jason Williams '91
  202.  
  203. DIM block% 512, menu% 256          :REM Data block to hold WIMP info
  204.  
  205. REM === Initialise the window manager ===
  206. $block%="TASK"
  207. SYS "Wimp_Initialise", 200, !block%, "ExampleApp" TO ,taskID%
  208.  
  209. PROCbarIcon                        :REM Put our icon on the icon bar
  210. PROCloadTemplates                  :REM Load window templates
  211.  
  212. quit% = FALSE
  213. mask% = 1
  214.  
  215. REPEAT                             :REM Main polling loop
  216.   SYS "Wimp_Poll", mask%, block% TO pollResult%
  217.  
  218.   CASE pollResult% OF
  219.     WHEN 1:                         REM A window needs redrawing
  220.       REM none of our windows need this
  221.  
  222.     WHEN 2:                         REM A window needs (re)opening
  223.       SYS "Wimp_OpenWindow",,block%
  224.  
  225.     WHEN 3:                         REM A window needs to be closed
  226.       SYS "Wimp_CloseWindow",,block%
  227.  
  228.     WHEN 6:                         REM A mouse button click
  229.       PROCbuttonClick
  230.  
  231.     WHEN 9:                         REM A menu item has been chosen
  232.       PROCmenuChoice
  233.  
  234.     WHEN 17,18:                     REM A WIMP message has arrived
  235.       IF block%!16 = 0 THEN quit%=TRUE
  236.   ENDCASE
  237. UNTIL quit%
  238.  
  239. REM === Tell WIMP we are quitting ===
  240. SYS "Wimp_CloseDown",taskID%
  241. END
  242.  
  243.  
  244.  
  245. DEF PROCbarIcon                      :REM Create iconbar icon
  246.   block%!0  = -1                     :REM Icon on right side of iconbar
  247.   block%!4  = 0                      :REM      min x position
  248.   block%!8  = 0                      :REM      min y position
  249.   block%!12 = 68                     :REM      max x (for standard icon size)
  250.   block%!16 = 68                     :REM      max y (")
  251.   block%!20 = &17003002              :REM Icon flags (colour, type, etc.)
  252.   $(block%+24) = "!Example"          :REM Icon sprite name
  253.  
  254.   SYS "Wimp_CreateIcon",,block% TO barIcon%
  255. ENDPROC
  256.  
  257.  
  258.  
  259. DEF PROCloadTemplates                :REM Load window templates
  260.   DIM templates% 1024
  261.  
  262.   currentptr% = templates%
  263.   bufferend%  = templates% + 1024
  264.  
  265.   SYS "Wimp_OpenTemplate",,"<Obey$Dir>.Templates"
  266.  
  267.     SYS "Wimp_LoadTemplate",,block%, currentptr%, bufferend%, -1, "info", 0
  268.     TO ,,currentptr%
  269.     SYS "Wimp_CreateWindow",,block% TO infoHandle%
  270.  
  271.     SYS "Wimp_LoadTemplate",,block%, currentptr%, bufferend%, -1, "window", 0
  272.     TO ,,currentptr%
  273.     SYS "Wimp_CreateWindow",,block% TO windowHandle%
  274.  
  275.   SYS "Wimp_CloseTemplate"
  276. ENDPROC
  277.  
  278.  
  279.  
  280. DEF PROCbuttonClick                  :REM Mouse click
  281.   window% = block%!12
  282.   icon%   = block%!16
  283.   button% = block%!8
  284.  
  285.   CASE window% OF
  286.     WHEN -2:                          REM Click on iconbar icon
  287.       IF button% = 2 THEN
  288.     PROCcreateMenu               :REM Menu: Pop up the menu
  289.       ELSE
  290.     block%!0 = windowHandle%     :REM Select/Adjust: Open window
  291.     SYS "Wimp_GetWindowState",,block%
  292.     SYS "Wimp_OpenWindow",,block%
  293.       ENDIF
  294.  
  295.     WHEN windowHandle%:               REM Click in main window
  296.       CASE icon% OF
  297.     WHEN 0:
  298.       VDU 7                      :REM Beep!
  299.  
  300.     WHEN 1:
  301.       VDU 7                      :REM Beep! Beep!
  302.       TIME = 0:REPEAT UNTIL TIME > 25
  303.       VDU 7
  304.  
  305.     WHEN 2:
  306.       VDU 7                      :REM Beep! Beep! Beep!
  307.       TIME = 0:REPEAT UNTIL TIME > 25
  308.       VDU 7
  309.       TIME = 0:REPEAT UNTIL TIME > 25
  310.       VDU 7
  311.       ENDCASE
  312.   ENDCASE
  313. ENDPROC
  314.  
  315.  
  316.  
  317. DEF PROCcreateMenu                   :REM Create icon-bar menu
  318.   xpos% = block%!0                   :REM Mouse x,y positions
  319.   ypos% = block%!4
  320.  
  321.   $menu%   = "Example"               :REM Title (up to 11 chars long)
  322.   menu%!12 = &00070207               :REM Standard colours
  323.   menu%!16 = 128                     :REM Menu width
  324.   menu%!20 = 40                      :REM Standard item height
  325.   menu%!24 = 0                       :REM Standard inter-item gap
  326.  
  327.   ptr%   = menu% + 28                :REM Menu item base pointer
  328.   ptr%!0 = 0                         :REM Flag word 1
  329.   ptr%!4 = infoHandle%               :REM info window hangs off here
  330.   ptr%!8 = &07000021                 :REM Standard flag word 2
  331.   $(ptr%+12) = "Info"                :REM Item text (Up to 11 chars)
  332.  
  333.   ptr%  += 24                        :REM Advance menu item base pointer
  334.   ptr%!0 = &80                       :REM Flag word 1 (End of list)
  335.   ptr%!4 = -1                        :REM NO submenu/subwindow
  336.   ptr%!8 = &07000021                 :REM Standard flag word 2
  337.   $(ptr%+12) = "Quit"                :REM Item text (Up to 11 chars)
  338.  
  339.   numitems% = 2                      :REM 2 menu items (info, quit)
  340.   ypos% = 96+(numitems%*40)
  341.  
  342.   xpos% -= 64                        :REM Menu pops up centred on pointer
  343.  
  344.   SYS "Wimp_CreateMenu",,menu%, xpos%, ypos%
  345. ENDPROC
  346.  
  347.  
  348.  
  349. DEF PROCmenuChoice                   :REM Choice made from the menu
  350.   mainitem% = block%!0
  351.  
  352.   CASE mainitem% OF
  353.     WHEN 0:                           REM Info
  354.       REM Do nothing in this case
  355.  
  356.     WHEN 1:                           REM Quit
  357.       quit% = TRUE
  358.   ENDCASE
  359. ENDPROC
  360.  
  361. -- 
  362. _________________  "I'd like to answer this question in two ways:
  363.   /____ _ _/_ __       First in my normal voice, and then
  364.  // / //_//_ /_/       in a silly, high-pitched whine." (Monty Python)
  365.  
  366.